# koroFileHeader at Yungoal acer
# Create: 2022-10-10 11:52:42
# LastEdit: 2022-10-12 16:00:25
"""验证器"""
__author__ = '749B'


from django.core.validators import EmailValidator, MaxValueValidator, MinValueValidator, RegexValidator

# Azure ID的正则表达式校验
validate_azure_id = RegexValidator(r'^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$')
validate_number_only = RegexValidator(r'[0-9]*')

# 校验是否是电子邮件列表，以分号分隔，分号后面可以加空格前面不行
def validate_email_list(value):
    """验证器: 电子邮件列表。以分号分隔，分号后面可以加空格前面不行"""
    validate_email = EmailValidator()
    for v in value.split(';'):
        validate_email(v.lstrip())

# Azure EA 的 商品编号(Part Number)
part_number = RegexValidator(r'[A-Z]{3}-[0-9]{5}')

# 0 ~ 100
validate_range100 = [MinValueValidator(0), MaxValueValidator(100)]
